<?php

$file = $_FILES['userfile']['tmp_name'];
//first check if the file isn't too large
$fileSize = filesize($file);
if($fileSize < 3500000){
	echo data_uri($file,'image/png');
}
else{ //file too big
	echo false;
}

//thanks wikipedia
function data_uri($file, $mime) 
{  
  $contents = file_get_contents($file);
  $base64   = base64_encode($contents); 
  return ('data:' . $mime . ';base64,' . $base64);
 
}
?>
